var AlertDefinitionTable = function() {
	var validator;
	return {
		init : function() {
			var tableId = "alert_def_table";
			util.initCheckBox(tableId);
			var checkBoxDivStr = '<div class="checker" onclick="util.selectCheckBox(\'' + tableId + '\', this)"><span><input type="checkbox" class="checkboxes"></span></div>';
			//查询字典信息列表
			function queryData(sSource, aoData, fnCallback) {
				aoData.push({
					"name" : "alertCode",
					"value" : $("#id_alertCode").val()
				});
				aoData.push({
					"name" : "alertName",
					"value" : $("#id_alertName").val()
				});
				aoData.push({
					"name" : "alertLevel",
					"value" : $("#id_alertLevel").val()
				});
				$.ajax({
					"type" : "post",
					"url" : sSource,
					"dataType" : "json",
					"data" : {
						"aoData" : JSON.stringify(aoData)
					},
					"success" : function(resp) {
						fnCallback(resp);
					}
				});
			};
			
			$('#alert_def_table').DataTable({
				"processing" : true,
				"serverSide" : true,
				"sAjaxSource" : "main/alertDefinition/findEntityPageByQuery.mvc",
				"fnServerData" : queryData,
				"pageLength" : 10,
				"sDom" : "<'row-fluid'r>t<'row-fluid'<'span6'i><'span6'p>>",
				"oLanguage" : util.getDToLanguage(),
				"columns" : [ {
					"data" : "pkId",
					"render" : function(data, type, full, meta) {
						return checkBoxDivStr; 
					},
					"bSortable" : false
				},
				{
					"data" : "alertCode",
					"bSortable" : false,
					"defaultContent" : ""
				}, {
					"data" : "alertName",
					"bSortable" : false,
					"defaultContent" : ""
				}, {
					"data" : "alertLevel",
					"bSortable" : false,
					"defaultContent" : ""
				}, {
					"data" : "alertCategory",
					"bSortable" : false,
					"defaultContent" : ""
				}],
				"fnDrawCallback" : function(oSetting) {
					util.clearSelected(tableId);
				}
			});
			
			//查询
			$("#btn_query").click(function(e) {
				var table = $('#alert_def_table').DataTable();
				table.draw(true);
			});
			//重置查询条件
			$("#btn_reset").click(function(e) {
				$("#id_alertCode").val("");
				$("#id_alertName").val("");
				$("#id_alertLevel").val("");
			});
			
			$(function(){
				$('.search-body input').bind('keyup', function(event) {
					if (event.keyCode == "13") {
						//回车执行查询
						$('.search-button #btn_query').click();
					}
				});
				util.getDictByParentKey(null, 'id_alertLevel', '全部','main/alertDefinition/findAlertLevelOpt.mvc');
			});
		}
	};
}();